/*

File: MyViewController.m
 //  HelloWorld
 //
 //  Created by Martin Le C. on 6/7/09.
 //  Copyright 2009 __MyCompanyName__. All rights reserved.
 
 */

#import "MyViewController.h"
#import "HelloWorldAppDelegate.h"
@implementation MyViewController

@synthesize username;
@synthesize password;
@synthesize loginButton;
- (void)viewDidLoad {
    // When the user starts typing, show the clear button in the text field.
    username.clearButtonMode = UITextFieldViewModeWhileEditing;
	password.clearButtonMode = UITextFieldViewModeWhileEditing;
	[loginButton addTarget:self action:@selector(signIn) forControlEvents:UIControlEventTouchDown];
	//[loginButton setTitle:@"Signing In" forState:UIControlStateSelected];
	//[loginButton setb]
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
	if (theTextField == username) {
		[username resignFirstResponder];
	}
	if (theTextField == password) {
		[password resignFirstResponder];
	}
	return YES;
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // Dismiss the keyboard when the view outside the text field is touched.
    [username resignFirstResponder];
	[password resignFirstResponder];
    // Revert the text field to the previous value.
    [super touchesBegan:touches withEvent:event];
}
- (void)dealloc {
	// To adhere to memory management rules, release the instance variables.
    // 'textField' and 'label' are objects in the nib file and are created when the nib
    // is loaded.
	[username release];
	[password release];
	[loginButton release];
	[super dealloc];
}
// called when the sign in button is touched
- (void)signIn {
	HelloWorldAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
	[appDelegate signIn:username.text p:password.text];
}

@end
